package com.example.demo;

import java.util.Objects;
import java.util.Optional;

public class LockTaskResult<T> {


    private  Boolean lockExpire;

    private  Optional<T> result;

    public LockTaskResult() {
    }

    LockTaskResult(Boolean lockExpire, Optional<T> result) {
        this.lockExpire = lockExpire;
        this.result = result;
    }

    public static <T> LockTaskResult<T> lockFail() {
        return new LockTaskResult<>(true, Optional.empty());
    }

    public static <T> LockTaskResult<T> lockSuccessAndResult(T t) {
        Objects.requireNonNull(t, "lock返回结果不能空");
        return new LockTaskResult<>(false, Optional.of(t));
    }


    public Boolean getLockExpire() {
        return lockExpire;
    }

    public Optional<T> getResult() {
        return result;
    }

    public void setLockExpire(Boolean lockExpire) {
        this.lockExpire = lockExpire;
    }

    public void setResult(Optional<T> result) {
        this.result = result;
    }

    @Override
    public String toString() {
        return "LockTaskResult{" +
                "lockExpire=" + lockExpire +
                ", result=" + result +
                '}';
    }
}
